﻿using Microsoft.AspNetCore.Mvc.Filters;
using System;

namespace PracticalDemo.Utility.Filter
{
    public class CustomActionFilterAttribute : Attribute, IActionFilter, IFilterMetadata, IOrderedFilter
    {
        public int Order { get; set; }

        public void OnActionExecuted(ActionExecutedContext context)
        {
            Console.WriteLine($"【{DateTime.Now}】\nThis is {typeof(CustomActionFilterAttribute)} OnActionExecuted");
        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            Console.WriteLine($"【{DateTime.Now}】\nThis is {typeof(CustomActionFilterAttribute)} OnActionExecuting");
        }
    }

    public class CustomResultFilterAttribute : Attribute, IResultFilter, IFilterMetadata, IOrderedFilter
    {
        public int Order { get; set; }

        public void OnResultExecuted(ResultExecutedContext context)
        {
            Console.WriteLine($"【{DateTime.Now}】\nThis is {typeof(CustomResultFilterAttribute)} OnResultExecuted");
        }

        public void OnResultExecuting(ResultExecutingContext context)
        {
            Console.WriteLine($"【{DateTime.Now}】\nThis is {typeof(CustomResultFilterAttribute)} OnResultExecuting");
        }
    }

    public class CustomResourceFilterAttribute : Attribute, IResourceFilter, IFilterMetadata, IOrderedFilter
    {
        public int Order { get; set; }

        public void OnResourceExecuted(ResourceExecutedContext context)
        {
            Console.WriteLine($"【{DateTime.Now}】\nThis is {typeof(CustomResourceFilterAttribute)} OnResourceExecuted");
        }

        public void OnResourceExecuting(ResourceExecutingContext context)
        {
            Console.WriteLine($"【{DateTime.Now}】\nThis is {typeof(CustomResourceFilterAttribute)} OnResourceExecuting");
        }
    }

    public class CustomControllerFilterAttribute : Attribute, IActionFilter, IFilterMetadata
    {
        public void OnActionExecuted(ActionExecutedContext context)
        {
            Console.WriteLine($"【{DateTime.Now}】\nThis is {typeof(CustomControllerFilterAttribute)} OnActionExecuted");
        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            Console.WriteLine($"【{DateTime.Now}】\nThis is {typeof(CustomControllerFilterAttribute)} OnActionExecuting");
        }
    }

    public class CustomGlobalFilterAttribute : Attribute, IActionFilter, IFilterMetadata
    {
        public void OnActionExecuted(ActionExecutedContext context)
        {
            Console.WriteLine($"【{DateTime.Now}】\nThis is {typeof(CustomGlobalFilterAttribute)} OnActionExecuted");
        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            Console.WriteLine($"【{DateTime.Now}】\nThis is {typeof(CustomGlobalFilterAttribute)} OnActionExecuting");
        }
    }
}
